// Created by Roman Novitsky on 22.04.2009


#region Imported Namespaces


using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;

using WtfManager.Framework;
using WtfManager.HierarchicalData;
using WtfManager.Utilities;


#endregion


namespace WtfManager.FileManager
{
  public class FileSystemItemToImageConverterExtension: Service, ITreeItemToImageConverterExtension
  {
    #region Properties/Indexers


    public override string Description
    {
      get
      {
        return "Converts File System Items to Images.";
      }
    }


    public override string Name
    {
      get
      {
        return "File System Item To Image Converter Extension";
      }
    }


    #endregion


    #region Methods


    protected override void OnStateChnaged()
    {
    }


    protected override FrameworkComponentState OnLoad()
    {
      return FrameworkComponentState.Loaded;
    }


    protected override void OnUnload()
    {
    }


    public ImageSource GetImage(TreeItem treeItem, bool largeIcon)
    {
      Debug.Assert(IsInitialized, "FileSystemItemToImageConverterExtension is not yet initialized.");

      if (treeItem is FileSystemItem)
      {
        var fileSystemItem = (FileSystemItem)treeItem;
        Icon icon = largeIcon ? fileSystemItem.LargeIcon : fileSystemItem.SmallIcon;

        return icon == null ? null : icon.ToImageSource();
      }

      return null;
    }


    


    protected override FrameworkComponentState OnInitialize()
    {
      return FrameworkComponentState.Initialized;
    }


    #endregion
  }
}